<template>
	<view style="flex-direction: column;">
		<image src="/static/index/know_banner.png" alt="" style='width:100%;height:140px;'> </image>
		<u-tabs :list="list1" @click="tabClick" :current="current" @change="tabChange" lineWidth="63px"
			lineColor="#1590EF" :activeStyle="{
			    color: '#1590EF',
			    fontWeight: 'bold',
			    transform: 'scale(1.05)'
			}" :inactiveStyle="{
			    color: '#606266',
			    transform: 'scale(1)'
			}" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;"></u-tabs>
		<view style="height: 2rpx;background-color: #ccc;margin-top: 10rpx;"></view>

		<view class="list_view" v-if="current==0">
			<view v-for="(item,index) in listData" :key="index">
				<view class="list_item">
					<view class="item_top">
						<view class="item_top_title">
							<text class="itemTop_left" style="float: left;">第{{item.index}}类:</text>
							<text class="itemTop_right">{{item.title}}</text>
						</view>
						<image class="item_img" src="/static/index/up2.png" mode="" @click="imgClick(item)">
						</image>
					</view>
					<view v-if="item.isShow">
						<view class="item_line"></view>
						<view v-for="(k,y) in item.children" :key="y">
							<view class="item_top_chren" @click="itemClick(k)">
								<text class="itemTop_left item_top_text">{{k.index}}:&nbsp;{{k.title}}</text>
								<u-icon name="arrow-right" color="#000000" size="30" style='display: inline-block;'>
								</u-icon>

							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view v-if="current==1">
			<view class="list_view">

				<view v-for="(item,index) in listData1" :key="index">
					<view class="list_item">
						<view class="item_top">
							<view class="item_top_title">
								<image class="img_left" src="/static/index/tj_icon.png" mode=""></image>
								<text class="itemTop_right1">{{item.title}}</text>
							</view>
							<image class="item_img" src="/static/index/up2.png" mode="" @click="imgClick1(item,index)">
							</image>
						</view>
						<view v-if="item.isShow">
							<view v-for="(k,y) in item.itemData" :key="y" @click="urlClick(k.id)">
								<view class="item_line"></view>
								<view class="item_top">
									<text class="itemTop_left1">{{k.rsName}}</text>
									<!-- <text class="text_right1">{{k.fileNo}}</text> -->
								</view>

								<view class="item_top">
									<view class="item_top_title">
										<text class="itemTop_left2">{{k.docDesc}}</text>
										<text class="itemTop_right2">{{k.modifyDate}}</text>
									</view>
									<image class="item_img" src="/static/index/vector.png" mode=""></image>
								</view>


							</view>
						</view>
					</view>
				</view>




			</view>

		</view>
	</view>
</template>

<script>
	import {
		knowregulatstandards,
		zskUrl
	} from '@/common/api/req.js'
	export default {
		data() {
			return {
				current: 0,
				list1: [{
					name: '危险品知识',
				}, {
					name: '政策法规',
				}],
				listData: [{
						index: "1",
						title: "爆炸品",
						show: true,
						children: [{
								index: "1.1",
								title: "有整体爆炸危险的物质和物品",
							},
							{
								index: "1.2",
								title: "有迸射危险，但无整体爆炸危险的物质和物品",
							},
							{
								index: "1.3",
								title: "有爆炸危险并有局部爆炸危险或局部迸射危险之一，或兼有这两种危险，但无整体爆炸危险的物质和物品",
							},
							{
								index: "1.4",
								title: "不呈现重大危险的物质和物品",
							},
							{
								index: "1.5",
								title: "有整体爆炸危险的非常不敏感物质",
							},
							{
								index: "1.6",
								title: "无整体爆炸危险的极端不敏感物品",
							},
						],
					},
					{
						index: "2",
						title: "气体",
						show: true,
						children: [{
								index: "2.1",
								title: "易燃气体",
							},
							{
								index: "2.2",
								title: "非易燃无毒气体",
							},
							{
								index: "2.3",
								title: "毒性气体",
							},
						],
					},
					{
						index: "3",
						title: "易燃液体",
						show: true,
					},
					{
						index: "4",
						title: "易燃固体、易于自燃的物质、遇水放出易燃气体的物质",
						show: true,
						children: [{
								index: "4.1",
								title: "易燃固体、自反应物质和固态退敏爆炸品",
							},
							{
								index: "4.2",
								title: "易于自燃的物质",
							},
							{
								index: "4.3",
								title: "遇水放出易燃气体的物质",
							},
						],
					},
					{
						index: "5",
						title: "氧化性物质和有机过氧化物",
						show: true,
						children: [{
								index: "5.1",
								title: "氧化性物质",
							},
							{
								index: "5.2",
								title: "有机过氧化物",
							},
						],
					},
					{
						index: "6",
						title: "毒性物质和感染性物质",
						show: true,
						children: [{
								index: "6.1",
								title: "毒性物质",
							},
							{
								index: "6.2",
								title: "感染性物质",
							},
						],
					},
					{
						index: "7",
						title: "放射性物质",
						show: true,
					},
					{
						index: "8",
						title: "腐蚀性物质",
						show: true,
					},
					{
						index: "9",
						title: "杂项危险物质和物品，包括危害环境的物质",
						show: true,
					},
				],


				listData1: [{
						title: '法律',
						isShow: false,
						itemData: []
					},
					{
						title: '行政法规',
						isShow: false,
						itemData: []
					}, {
						title: '部门规章',
						isShow: false,
						itemData: []
					}, {
						title: '标准规范',
						isShow: false,
						itemData: []
					},
					{
						title: '行政规范',
						isShow: false,
						itemData: []
					},
				]
			};
		},

		methods: {
			urlClick(id) {
				zskUrl(id).then(res => {
					let url = res.data.data.files[0]?.url
					// console.log(url, '+++');
					// uni.downloadFile({ //通过uniapp的api下载下来,app端会调用对应软件打开
					// 	url: url,
					// 	success: function(res) {
					// 		var filePath = res.tempFilePath;
					// 		uni.openDocument({
					// 			filePath: filePath,
					// 			success: function(FileRes) {
					// 				console.log('打开文档成功');
					// 			}
					// 		});
					// 	}
					// });
					if (!url) {
						uni.showToast({
							title: "没有详情文件",
							icon: 'none'
						})
						return false;
					}
					this.$goBack('../knowledge/zskpdf?url=' + url,
						2);
				})

			},
			getData(busiType) {
				knowregulatstandards({
					busiType: busiType + 1,
					rsName: "",
					releaseDate: "",
					current: 1,
					size: 1000,
					total: 0
				}).then(res => {
					console.log(res, '++++++++')
					let list = res.data.data.records
					if (busiType == 0) {
						this.listData1[busiType].itemData = list
					} else if (busiType == 1) {
						this.listData1[busiType].itemData = list
					} else if (busiType == 2) {
						this.listData1[busiType].itemData = list
					} else if (busiType == 3) {
						this.listData1[busiType].itemData = list
					} else if (busiType == 4) {
						this.listData1[busiType].itemData = list
					}
				})
			},
			// 监听点击右上角事件
			onNavigationBarButtonTap(e) {
				if (this.current == 0) {
					this.$goBack('../knowledge/index', 2);
				} else {
					this.$goBack('../knowledge/zcQuery', 2);
				}



			},
			tabChange(e) {
				console.log("----", e);
				this.current = e.index
			},
			tabClick() {},
			itemClick(k) {
				this.$goBack('../knowledge/knowledge_danger?data=' + JSON.stringify({
					termOther: k.index
				}));
			},
			imgClick(item) {
				this.$set(item, 'isShow', !item.isShow)
			},
			imgClick1(item, index) {
				this.$set(item, 'isShow', !item.isShow)
				this.getData(index)
			}
		}
	}
</script>

<style lang="scss">
	.search {
		padding: 20rpx 30rpx;
	}

	.list_view {
		height: 300rpx;
		padding: 30rpx;

		.list_item {
			background-color: #ffffff;
			// box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.16);
			opacity: 1;
			// padding: 5rpx;
			border-radius: 10rpx;
			margin-bottom: 30rpx;


			.item_top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 15rpx 0px;
				// margin: 20rpx 0rpx;
				background-color: #EAF7FF;
				// border: 1px red solid;

				.item_top_title {
					flex: 1;
					padding: 0 0 0 10px;

					.img_left {
						width: 24rpx;
						height: 28rpx;
						margin-right: 10rpx;
					}

					.itemTop_left {
						font-size: 34rpx;
						color: #154769;
					}

					.itemTop_left2 {
						font-size: 26rpx;
						color: #333333;
					}

					.itemTop_left1 {
						font-size: 30rpx;
						color: #666666;
					}

					.itemTop_right {
						width: 500rpx;
						display: inline-block;
						font-size: 34rpx;
						color: #154769;
						font-weight: 700;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						// border: 1px red solid;

					}

					.itemTop_right1 {
						font-size: 34rpx;
						color: #1590EF;
					}

					.itemTop_right2 {
						margin-left: 20rpx;
						font-size: 26rpx;
						color: #999999;
					}
				}

				.item_img {
					width: 48rpx;
					height: 36rpx;
					margin: 0 5px 0 0;
				}

				.text_right {
					width: 40rpx;
					height: 30rpx;
					color: #1590EF;
				}

				.text_right1 {
					color: #CA2828;
					font-size: 26rpx;
				}
			}

			.item_top_chren {
				// border: 1px red solid;
				width: 100%;
				display: inline-block;
				padding: 10px 0px;
				background: #F6F7F9;
				margin: 5px 0;
				border-radius: 10rpx;
			}

			.item_top_text {
				width: 88%;
				display: inline-block;
				padding: 0 10px;
				// white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;

			}

			.item_line {
				height: 2rpx;
				background-color: #eeeeee;
			}

		}
	}
</style>